package com.navi.loaddata.loadService.impl.Dcdata.cell2;

import com.navi.loaddata.core.errorLog.ErrorCode;
import com.navi.loaddata.core.etlException.ETLException2;
import com.navi.loaddata.core.mesEntity.MesProductEntity;
import com.navi.loaddata.core.mesEntity.SpcDcdata;
import com.navi.loaddata.core.oracleEntity.EtlPdsGlassV;
import com.navi.loaddata.core.repository.impl.MesRepositoryImpl;
import com.navi.loaddata.core.util.ProcessUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author jay
 */
@Service
public class ProcessDcDataServiceCELL23 {

    @Autowired
    private MesRepositoryImpl daomes;
    private static final Logger logger = LoggerFactory.getLogger(ProcessDcDataServiceCELL23.class);


    public EtlPdsGlassV processDcData(SpcDcdata d) throws Exception {
        EtlPdsGlassV etlPdsGlassV = new EtlPdsGlassV();
        try {
            etlPdsGlassV.setStepId(d.getProcessoperationname());
            etlPdsGlassV.setSubEquipId(d.getUnitname());
            etlPdsGlassV.setChipId(d.getMaterialname());
            etlPdsGlassV.setGlassId(d.getMaterialname().substring(0,10));
            etlPdsGlassV.setChipId(d.getMaterialname());
            etlPdsGlassV.setGlassEndTime(d.getEventtime());
            etlPdsGlassV.setProductId(d.getProductspecname());
            etlPdsGlassV.setRouteId(d.getProcessflowname());
            etlPdsGlassV.setLotId(d.getLotname());
            etlPdsGlassV.setEquipId(d.getMachinename());
            etlPdsGlassV.setRunMode(d.getRunmode());
            if (StringUtils.isEmpty(d.getRecipename())) {
                etlPdsGlassV.setRecipeId(d.getProductspecname());
            } else {
                etlPdsGlassV.setRecipeId(d.getRecipename());
            }
            etlPdsGlassV.setOperatorId(d.getEventuser());
            etlPdsGlassV.setOwnerId(d.getOwnercode());
            etlPdsGlassV.setMesLinkKry(d.getMeslinkkey());
            etlPdsGlassV.setChipNo(ProcessUtil.processString(d.getMaterialname().substring(d.getMaterialname().length()-2,d.getMaterialname().length())));
            etlPdsGlassV.setArrayGlassId(ProcessUtil.processString(d.getMaterialname().substring(0,10)));
            String CfGlassId=daomes.find(MesProductEntity.class,"from MesProductEntity where productname='"+d.getMaterialname()+"'").get(0).getCfproductname();
            etlPdsGlassV.setCfGlassId(ProcessUtil.processString(CfGlassId));
        }catch (Exception e){
            throw new ETLException2(ErrorCode.ERROR_PROCESS_MES2ORA_PDS_GLASS,e);
        }
//        etlPdsGlassV.setTaShift(); todo
        return etlPdsGlassV;
    }

}
